<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:74:"D:\phpStudy\WWW\oa\public/../application/admin\view\branch\branchsave.html";i:1514531683;}*/ ?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title>添加部门</title>
    <link rel="stylesheet" href="__CSS__/pintuer.css">
    <link rel="stylesheet" href="__CSS__/admin.css">
    <link rel="stylesheet" href="__STATIC__/css/layui.css">
    <script src="__STATIC__/layui.js"></script>
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 部门信息</strong>&emsp;<a
            style="color: #3a4bfb;font-weight: bold " href="javascript:history.go(-1)">返回上一步</a></div>
    <div style="width: 600px;height: 350px;border:1px solid #ffffee;margin: 0 auto" class="body-content">
        <form method="post" class="layui-form" action="">
            <div class="layui-form-item">
                <div style="margin-left:15%;width: auto; height: auto;text-align: center" class="layui-inline">
                    <label style="float: left;margin-top: 3%" class="layui-form-lable">主体：</label>
                    <div class="layui-input-inline">
                        <select style="height: 30px; width: 160px;text-align: center" id="region" lay-filter="region_id"
                                lay-search="" name="region_id">
                            <?php if(is_array($region) || $region instanceof \think\Collection || $region instanceof \think\Paginator): $i = 0; $__LIST__ = $region;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$re): $mod = ($i % 2 );++$i;if($re['id'] == $branch['region_id']): ?>
                            <option style="text-align: center" selected="selected" value="<?php echo $re['id']; ?>"><?php echo $re['region']; ?>
                            </option>
                            <?php else: ?>
                            <option style="text-align: center" value="<?php echo $re['id']; ?>"><?php echo $re['region']; ?></option>
                            <?php endif; endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
            </div>
            <input name="id" value="<?php echo $branch['id']; ?>" type="hidden">
            <div class="layui-form-item">
                <div style="margin-left:10.5%;width: auto; height: auto;text-align: center" id="spanss"
                     class="layui-inline">
                    <!--部門-->
                    <label style="float: left;margin-top: 1.5%" class="layui-form-lable">部门名称：</label>
                    <div class="layui-input-inline">
                        <input style="text-align: center;width: 160px;height: 30px" lay-verify="required"
                               placeholder="请填写部门名称" value="<?php echo $branch['branch']; ?>" name="branch" class="layui-input"
                               type="text" id="branch">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div style="margin-left:12.5%;width: auto; height: auto;text-align: center" class="layui-inline">
                    <label style="float: left;margin-top: 1.5%" class="layui-form-lable">负责人：</label>
                    <div class="layui-input-inline">
                        <input style="text-align: center;width: 160px;height: 30px" lay-verify="required"
                               placeholder="请填写部门负责人" value="<?php echo $branch['ch_name']; ?>" name="ch_name" class="layui-input"
                               type="text" id="ch_name">
                    </div>
                </div>
            </div>
            <div style="margin-top: 20px;" class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo">立即修改</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">
    /*function cw() {
     var region = $('#region').val();
     var branch = $('#branch').val();
     var ch_name = $('#ch_name').val();
     var sub = $('#sub').val();
     $.ajax({
     url: "<?php echo url('Branch/branchadd'); ?>",
     type: "post",
     data: {"region_id": region, "branch": branch, "ch_name": ch_name, "sub": sub},
     dataType: "json",
     success: function (aa) {
     if (aa) {
     alert("添加成功");
     } else {
     alert("添加失败")
     }
     }
     })
     }*/
    /*function zhuti(region_id) {
     $('#spanss').html('');
     var html = '';
     //alert(region_id);
     $.ajax({
     url: "<?php echo url('Branch/admin'); ?>",
     type: "post",
     data: {"region_id": region_id},
     dataType: "json",
     success: function (res) {
     if (res) {
     $.each(res, function (k, v) {
     //alert(v.id);
     //console.log(v.id);
     html += '<option value="' + v.id + '">' + v.branch + '</option>';
     });
     var html2 = '部门&emsp;<select style="height: 30px; width: 160px;text-align: center" name="branch_id">'
     + '<option value="">请选择部门</option>'
     + html +
     '</select>';

     $("#spanss").html(html2);
     }
     }
     })
     }*/
</script>
<script>
    layui.use('form', function () {
        var form = layui.form;
        //加载
        var index = layer.load(1, {time: 10*1000});
        //关闭
        layer.close(index);
        //监听提交
        form.on('submit(demo)', function (data_d) {
            // console.log(JSON.stringify(data.field));
            /*layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             });*/
            var datas = JSON.stringify(data_d.field);
            //console.log(datas);
            var submit = '修改';
            $.ajax({
                type: "post",
                url: "<?php echo url('Branch/branchsave_sub'); ?>",
                data: {'data': datas, 'sub': submit},
                dataType: "json",
                success: function (res) {
                    //console.log(res);
                    //alert(res);
                    if (res == 1) {
                        //alert(res);
                        //console.log(res);
                        layer.msg('修改成功');
                        window.setTimeout("window.location=\"<?php echo url('Branch/admin'); ?>\"", 2000);
                        //window.location.href="<?php echo url('Stafflist/admin'); ?>"
                    } else {
                        if (res == 2) {
                            layer.msg('提示：部门名称修改成功,负责人修改失败，请输入本公司员工的名字');
                        } else {
                            layer.msg('提示：部门修改失败,部门名称可能已被使用');
                        }
                    }
                }
            });

            /* layer.alert(JSON.stringify(data.field), {
             title: '最终的提交信息'
             });*/
            return false;
        });
    })
</script>
</html>